package shop.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import shop.model.User;
import shop.repository.UserRepository;

@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    //密码重复输入
    public boolean verUserpassword(String p1,String p2){
        if(p1.equals(p2))
            return true;
        return false;
    }

    //账号注册,存在false,成功注册true
    public boolean regUser(User user){
        //存在返回true
        if(userRepository.existsById(user.getUtele())){
            return false;
        }else {
            userRepository.save(user);
            return true;
        }
    }

   //账号登录
    public User logUser(String utele,String upassword){
        User user = userRepository.login(utele,upassword);
        return user;
    }

    //修改密码
    public boolean modifyUserpassword(String utele,String upassword){
        User user = userRepository.modify(upassword,utele);
        if(user == null)
            return false;
        else
            return true;
    }



}
